package de.fhaugsburg.games.boardgames.scrabble.testing;

import java.util.ArrayList;
import java.util.List;

import de.fhaugsburg.games.boardgames.Board;
import de.fhaugsburg.games.boardgames.IPool;
import de.fhaugsburg.games.boardgames.scrabble.IScrabbleEngine;
import de.fhaugsburg.games.boardgames.scrabble.LetterPiece;
import de.fhaugsburg.games.boardgames.scrabble.ScrabbleBoard;
import de.fhaugsburg.games.boardgames.scrabble.ScrabbleEngine;
import de.fhaugsburg.games.boardgames.scrabble.ScrabblePlayer;
import de.fhaugsburg.games.boardgames.scrabble.State;
import de.fhaugsburg.games.boardgames.scrabble.consoleui.BoardView;
import de.fhaugsburg.games.boardgames.scrabble.managment.GridPoint;
import de.fhaugsburg.games.boardgames.scrabble.managment.ScrabblePool;
import de.fhaugsburg.games.boardgames.scrabble.strategy.GreedyScrabbleBot;
import junit.framework.TestCase;

public class ScrabbleEngineTest extends TestCase {
	private IScrabbleEngine engine;
	private Board expectedBoard;
	private GridPoint g8,h8,g9;
	private List<LetterPiece> letterSet;
	private BoardView view;
	private GreedyScrabbleBot bot;
	
	
	

	protected void setUp() throws Exception {
		super.setUp();				
		engine = new ScrabbleEngine(new ScrabblePool()); //kein RandomPool!
		expectedBoard = new ScrabbleBoard();
		engine.addPlayer(new ScrabblePlayer("Fritz"));
		engine.addPlayer(new ScrabblePlayer("Hans"));
		g8 = new GridPoint(6,7);
		h8 = new GridPoint(7,7);
		g9 = new GridPoint(6,8);
		letterSet = new ArrayList<LetterPiece>();
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.E));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.E));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.E));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.R));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.R));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.S));
		letterSet.add((LetterPiece) engine.getPool().take(LetterPiece.S));
		engine.setCurrentPlayer(engine.getPlayerList().get(0));
		for (int i = 0; i < engine.getPlayerList().size(); i++) { // die spielerliste
			// durchlaufen			
				engine.getPlayerList().get(i).receiveAll(letterSet);			
		}	
		view = new BoardView();
		bot = new GreedyScrabbleBot(engine.getScrabbleBoard());
		
	}
	public void testSituation(){
		engine.setCurrentState(State.DROPPING, LetterPiece.E, g8);
		engine.setCurrentState(State.DROPPING, LetterPiece.R, h8);
		expectedBoard.putPiece(LetterPiece.E, g8);
		expectedBoard.putPiece(LetterPiece.R, h8);
		assertTrue(engine.getScrabbleBoard().equals(expectedBoard));		
		engine.getWordManager().reset();
		engine.setCurrentPlayer(engine.getPlayerList().next());
//		engine.setCurrentState(State.DROPPING, LetterPiece.S, g9);
		expectedBoard.putPiece(LetterPiece.S, g9);
		bot.startBot();
		view.renderScrabbleBoard(engine.getScrabbleBoard());
		assertTrue(engine.getScrabbleBoard().equals(expectedBoard));
		
	}
	

}
